<template>
  <div>
<h1>修改页面</h1>
<table>
  <tr>
    <td>投资名称：</td>
    <td><input type="text" v-model="state.TName"></td>
  </tr>
  <tr>
    <td>投资总额度：</td>
    <td><input type="text" v-model="state.ZongE"></td>
  </tr>
  <tr>
    <td></td>
    <td><input type="button" value="修改" @click="xiu"></td>
  </tr>
</table>
  </div>
</template>

<script setup lang="ts">
import {reactive,toRefs,onMounted} from 'vue'
import axios from 'axios'
import {useRoute,useRouter} from 'vue-router'
const router=useRouter()
const route=useRoute()

let data=reactive({
  state:{
    TName:'',
    ZongE:''
  },
})

let {state}=toRefs(data)

onMounted(()=>{
  getData()
})

const getData=()=>{
axios({
  url:'/api/TouZi/FanTian',
  method:'get',
  params:{
    Tid:route.query.Tid
  }
})
.then(res=>{
  state.value=res.data.data
})
.catch(err=>{
  console.log(err);
  
})
}

const xiu=()=>{
  axios({
    url:'/api/TouZi/Update',
    method:'post',
    data:state.value
  })
  .then(res=>{
    if(res.data.data==-1){
      alert('该投资名称已存在');
      return;
    }
    else if(res.data.data>0){
      alert('修改成功');
      router.push('/show');
    }
    else{
      alert('修改失败');
    }
  })
}
</script>

<style scoped>

</style>